

#include <windows.h>
#include <unistd.h>
#include <stdio.h>
#include <SDL/SDL.h>

typedef struct
{
    SDL_Rect pos;
    int val;
} cases;


{
    SDL_Surface *screen;
    SDL_Surface *image, *image0, *image1, *image2, *image3, *image4, *image5 , *temp;
    SDL_Rect src ,src0 ,src01 ,src1 , src2, src3, src4, src5, dest, dest0,dest01 , dest1, dest2, dest3,dest4 , dest5;
    SDL_Event event ;
    cases T[5];
    int  i,p,n,j,
             x,done=0 ;
    cases aux;
    T[0].val=18;
    T[1].val=9;
    T[2].val=6;
    T[3].val=22;
    T[4].val=11;
    T[0].pos.x=284 ;
    T[0].pos.y=444;
    T[1].pos.x=379 ;
    T[1].pos.y=444;
    T[2].pos.x=462 ;
    T[2].pos.y=444 ;
    T[3].pos.x=563 ;
    T[3].pos.y=444 ;
    T[4].pos.x=654 ;
    T[4].pos.y=444 ;
    if (SDL_Init(SDL_INIT_VIDEO) != 0)
    {
        printf("Unable to initialize SDL: %s\n", SDL_GetError());
        return 7;
    }
    screen = SDL_SetVideoMode(1054,688, 32, SDL_HWSURFACE | SDL_DOUBLEBUF );
    if (screen == NULL)
    {
        printf("Unable to set video mode: %s\n", SDL_GetError());
        return 8;

}
    image = SDL_LoadBMP("img/1.bmp");
    if (image == NULL)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 9;
    }


    image0 = SDL_LoadBMP("img/tab.bmp");
    if (image0 == NULL)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 9;
    }

    image1 = SDL_LoadBMP("img/18.bmp");
    if (image1 == NULL)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 1;
    }
    image2 = SDL_LoadBMP("img/9.bmp");
    if (image2 == NULL)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 2;
    }
    image3 = SDL_LoadBMP("img/6.bmp");
    if (image3 == NULL)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 3;
    }
    image4 = SDL_LoadBMP("img/22.bmp");
    if (image4 == NULL)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 4;
    }
    image5 = SDL_LoadBMP("img/11.bmp");
    if (image5 == NULL)
    {
        printf("Unable to load bitmap: %s\n", SDL_GetError());
        return 5;
    }
src.x = 0;
    src.y = 0;
    src.w = image->w;
    src.h = image->h;
    dest.x = 0;
    dest.y = 0;

    dest0.x = 266;
    dest0.y = 423;
    dest0.w = image->w;
    dest0.h = image->h;

    src1.x = 0;
    src1.y = 0;
    src1.w = image->w;
    src1.h = image->h;
    dest1.x = T[0].pos.x;
    dest1.y = T[0].pos.y;
    dest1.w = image->w;
    dest1.h = image->h;
    src2.x = 0;
    src2.y = 0;
    src2.w = image->w;
    src2.h = image->h;
    dest2.x = T[1].pos.x;
    dest2.y = T[1].pos.y;
    dest2.w = image->w;
    dest2.h = image->h;
    src3.x = 0;
    src3.y = 0;
    src3.w = image->w;
    src3.h = image->h;
    dest3.x = T[2].pos.x;
    dest3.y = T[2].pos.y;
    dest3.w = image->w;
    dest3.h = image->h;
    src4.x = 0;
    src4.y = 0;
    src4.w = image->w;
    src4.h = image->h;
    dest4.x = T[3].pos.x;
    dest4.y = T[3].pos.y;
    dest4.w = image->w;
    dest4.h = image->h;
    src5.x = 0;
    src5.y = 0;
    src5.w = image->w;
    src5.h = image->h;
    dest5.x = T[4].pos.x;
    dest5.y = T[4].pos.y;
    dest5.w = image->w;
    dest5.h = image->h;
    i=0;
    while (i<5 || done ) //game loop
    {
        /************************** Game Logic : Tri des tableaux + ecoute des events **********************/
        /*********************ecoute des evenements ******************************/
        while(SDL_WaitEvent(&event) && !done)
        {
            switch(event.type)
            {
            case SDL_KEYDOWN:
                if(event.key.keysym.sym == SDLK_SPACE)
                    done =1;
                break;
            }
        }
        /******************** Tri insertion ************************/




T[i].pos.x=T[i+1].pos.x;
T[i+1].pos.x=T[i].pos.x-10;




/**************************tri_bulle*****************************/


/*************************tri_selection**********************/



/*************************tri rapide******************************/


      /*******************affichage du tableau initial (2)**************************/
        SDL_BlitSurface(image, &src, screen, &dest);
         SDL_BlitSurface(image0, &src, screen, &dest);

        SDL_BlitSurface(image1, &src1, screen, &dest1);
        SDL_BlitSurface(image2, &src2, screen, &dest2);
        SDL_BlitSurface(image3, &src3, screen, &dest3);
        SDL_BlitSurface(image4, &src4, screen, &dest4);
        SDL_BlitSurface(image5, &src5, screen, &dest5); //afficher le premier tableau
        /*******************affichage du tableau resultat (2)**************************/
        SDL_BlitSurface(image1, NULL , screen, &T[1].pos);
        SDL_BlitSurface(image2, NULL, screen, &T[2].pos);
        SDL_BlitSurface(image3, NULL, screen, &T[3].pos);
        SDL_BlitSurface(image4, NULL ,screen, &T[4].pos);
        SDL_BlitSurface(image5, NULL, screen, &T[5].pos);
        /*********************** copie de screen dans carte graphique (3 + 4) ***********************/

        SDL_Flip(screen);

        i++;


    }
    SDL_FreeSurface(image1);
    SDL_FreeSurface(image2);
    SDL_FreeSurface(image3);
    SDL_FreeSurface(image4);
    SDL_FreeSurface(image5);
    return(0);
}




